package com.rrqs.net;

import android.text.TextUtils;

/**
 * url 后缀
 */
public class UrlSuffix {

	private String action;
	private String client;
	private String device;
	private String platform;
	private String random;
	private String token;

	private UrlSuffix(Builder builder) {
		this.action = builder.action;
		this.client = builder.client;
		this.device = builder.device;
		this.platform = builder.platform;
		this.random = builder.random;
		this.token = builder.token;
	}

	public static class Builder{

		// 变长字符串，接口的唯一标识
		private String action;
		// 用户设备类型（pda，pad，phone）
		private String client;
		// 设备唯一标识（IMEI）
		private String device;
		// 服务平台：ns护士站、ds医生站、ss管理
		private String platform;
		// 随机数
		private String random;
		// 用户标识，登录接口返回
		private String token;

		public Builder() {
			super();
		}

		/**
		 * 
		 * @param action		接口的唯一标识
		 * @param client		用户设备类型（pda，pad，phone）
		 * @param device		设备唯一标识（IMEI）
		 * @param platform		服务平台：ns护士站、ds医生站、ss管理
		 * @param random		随机数
		 * @param token			用户标识，登录接口返回
		 */
		public Builder(String action, String client, String device, String platform, String random, String token) {
			super();
			this.action = action;  
			this.client = client;  
			this.device = device;  
			this.platform = platform;  
			this.random = random;  
			this.token = token;  
		}
		
		/**
		 * @param action		接口的唯一标识
		 * @param client		用户设备类型（pda，pad，phone）
		 * @param device		设备唯一标识（IMEI）
		 * @param platform		服务平台：ns护士站、ds医生站、ss管理
		 * @param token			用户标识，登录接口返回
		 */
		public Builder(String action, String client, String device, String platform, String token) {
			super();
			this.action = action;  
			this.client = client;  
			this.device = device;  
			this.platform = platform;  
			this.token = token;  
		}
		
		public Builder setAction(String action) {
			this.action = action;
			return this;
		}

		public Builder setClient(String client) {
			this.client = client;
			return this;
		}

		public Builder setDevice(String device) {
			this.device = device;
			return this;
		}


		public Builder setPlatform(String platform) {
			this.platform = platform;
			return this;
		}

		public Builder setRandom(String random) {
			this.random = random;
			return this;
		}

		public Builder setToken(String token) {
			this.token = token;
			return this;
		}

		//构造器入口
		public UrlSuffix build(){
			return new UrlSuffix(this);
		}
	}

	public String toString() {
		
		String str = "";
		str += "a" + action;
		str += "&c" + client;
		str += "&d" + device;
		str += "&p" + platform;
		if (!TextUtils.isEmpty(random)) {
			str += "&r" + random;
		}
		str += "&t" + token;
		return str;
	}
}
